#include"mqc_connection.hpp"


void cb(mq::ClientChannel::ptr& channel,const std::string& tag,const mq::BasicProperty* bp,const std::string& body){
    std::cout<<tag<<"消费了："<<body<<std::endl;
    channel->basicAck(bp->id());
}

int main(int argc,char* argv[]){
    if(argc != 2){
        std::cout<<"you should: "<<argv[0]<<" "<<"queue_name"<<std::endl;
        return 0;
    }
    std::string ip = "127.0.0.1";
    int port = 8080;
    mq::AsyncWorker::ptr worker = std::make_shared<mq::AsyncWorker>();
    mq::ClientConnection client(ip,port,worker);
    client.connect();
    mq::ClientChannel::ptr clp = client.openChannel();
    google::protobuf::Map<std::string,std::string> gmap;
    clp->declareExchange("exchange1",mq::ExchangeType::FAOUT,true,false,gmap);
    clp->declareQueue("queue1",true,false,false,gmap);
    clp->declareQueue("queue2",true,false,false,gmap);
    clp->bind("exchange1","queue1","queue1");
    clp->bind("exchange1","queue2","news.music.#");
    auto fun =  std::bind(cb,clp,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3);
    clp->basicConsume("consumer1",argv[1],false,fun);
    
    while(1) std::this_thread::sleep_for(std::chrono::seconds(3));
    clp->closeChannel();

    return 0;
}